package com.ruoyi.web.controller.Tour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TourViolation;
import com.ruoyi.system.service.ITourViolationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 违规记录管理Controller
 *
 * @author once
 * @date 2020-10-02
 */
@RestController
@RequestMapping("/Tour/violation")
public class TourViolationController extends BaseController
{
    @Autowired
    private ITourViolationService tourViolationService;

    /**
     * 查询违规记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourViolation tourViolation)
    {
        startPage();
        List<TourViolation> list = tourViolationService.selectTourViolationList(tourViolation);
        return getDataTable(list);
    }

    /**
     * 导出违规记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:export')")
    @Log(title = "违规记录管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourViolation tourViolation)
    {
        List<TourViolation> list = tourViolationService.selectTourViolationList(tourViolation);
        ExcelUtil<TourViolation> util = new ExcelUtil<TourViolation>(TourViolation.class);
        return util.exportExcel(list, "violation");
    }

    /**
     * 获取违规记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:query')")
    @GetMapping(value = "/{violationId}")
    public AjaxResult getInfo(@PathVariable("violationId") Long violationId)
    {
        return AjaxResult.success(tourViolationService.selectTourViolationById(violationId));
    }

    /**
     * 新增违规记录管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:add')")
    @Log(title = "违规记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourViolation tourViolation)
    {
        return toAjax(tourViolationService.insertTourViolation(tourViolation));
    }

    /**
     * 修改违规记录管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:edit')")
    @Log(title = "违规记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourViolation tourViolation)
    {
        return toAjax(tourViolationService.updateTourViolation(tourViolation));
    }

    /**
     * 删除违规记录管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:violation:remove')")
    @Log(title = "违规记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{violationIds}")
    public AjaxResult remove(@PathVariable Long[] violationIds)
    {
        return toAjax(tourViolationService.deleteTourViolationByIds(violationIds));
    }
}
